package com.xunyin.utils;

import java.util.Random;
import java.util.UUID;

/**
 * @author: Administration
 * @description: 生成随机码的工具类
 */
public class RandomUtil {
    /**
     * 生成前缀+32位编码 用作id
     *
     * @return string
     */
    public static String genarateId(String prefix) {
        String uuid = prefix + UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
    }

    /**
     * 产生随机的n位数
     *
     * @return
     */
    public static String getRandom(int n) {

        int basic = 1;

        for (int i = 0; i < n; i++) {
            basic = basic * 10;
        }


        Random rad = new Random();

        String result = rad.nextInt(basic) + "";

        for (int j = result.length(); j < n; j++) {
            result = "0" + result;
        }


//
//		if(result.length()==1){
//			result = "0" + result;
//		}
        return result;
    }
}
